readyFunc = function(){
    return {
        init: function(){
        	new MenuButton(4, '#menuDiv');
        	initGrid();
    	}
    };
}();

jQuery(readyFunc.init);

function initGrid() {
	$('#datagrid').datagrid({
		url:__MANAGER+'liverDocMainQuery.do',
		idField: 'docId',
		columns:[[
			{field:'checked',checkbox:true,halign:'center'},
		    {field:'docNo',title:'序号',width:120},
			{field:'name',title:'姓名',width:120},
			{field:'sex',title:'性别',width:120,formatter:function(value) {
				return value == 1 ? '男' : '女';
			}},
			{field:'surveyDay',title:'调查时间',width:120},
			{field:'birthday',title:'出生日期',width:120},
			{field:'age',title:'年龄',width:120},
			{field:'marriy',title:'婚况',width:120,formatter:function(value) {
				return value == 1 ? '未婚' 
						: (value == 2 ? '已婚' 
								: (value == 3 ? '离婚'
										: (value == 4 ? '丧偶' 
												: '')));
			}},
			{field:'jobName',title:'职业',width:120},
			{field:'nationality',title:'民族',width:120},
			{field:'disCourse',title:'病程',width:120},
			{field:'stature',title:'身高',width:120},
			{field:'weight',title:'体重',width:120},
			{field:'bloodType',title:'血型',width:120,formatter:function(value) {
				return value == 1 ? 'A型' 
						: (value == 2 ? 'B型' 
								: (value == 3 ? 'AB型'
										: (value == 4 ? 'O型' 
												: '')));
			}},
			{field:'disSource',title:'病人来源',width:120,formatter:function(value) {
				return value == 1 ? '住院病人' 
						: (value == 1 ? '门诊病人' : '');
			}},
			{field:'disSourceNo',title:'住院号',width:120},
			{field:'homeAddress',title:'家庭住址',width:250,halign:'center'},
			{field:'homePhone',title:'住宅电话',width:120},
			{field:'inputDate',title:'录入时间',width:120},
			{field:'inputUserName',title:'录入人',width:120}
		]],
		pagination: true,
	    pagePosition: 'bottom',
	    pagination: (S4J.utils.pagination())
	}); 
}

function query(tb) {
	$('#datagrid').datagrid('load',{
		'patientDoc.name' : mainQueryForm.name.value
	});
}

function append(tb) {
	debugger;
	$.ajax({
		url : __SHOWMAINVIEW+'_mduno=docmgr_liverdocmgr_docEdit',
		type : "GET",
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(_html) {
			$('#docEditWindow').window({
				width: 500,
				height: 150,
				modal: true,
				title: '创建档案',
				minimizable: false,
				maximizable: false,
				maximized: true,
				content: _html
			});
			$('#Tab_docEdit').tabs('disableTab', 1);
			$('#Tab_docEdit').tabs('disableTab', 2);
			$('#Tab_docEdit').tabs('disableTab', 3);
			$('#Tab_docEdit').tabs('disableTab', 4);
			$('#Tab_docEdit').tabs('disableTab', 5);
		}
	});
}

function edit(tb) {
	var row = $('#datagrid').datagrid('getSelected');
	if(row == null) {
		S4J.utils.showMessage('请选择一条记录');
		return;
	}
	var rows = $('#datagrid').datagrid('getSelections');
	if(rows.length > 1) {
		S4J.utils.showMessage('只能选择一条记录');
		return;
	}
	var docId = row.docId;
	$.ajax({
		url : __SHOWMAINVIEW+'_mduno=docmgr_liverdocmgr_docEdit&docId='+docId,
		type : "GET",
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(_html) {
			$('#docEditWindow').window({
				width: 500,
				height: 150,
				modal: true,
				title: '编辑档案',
				minimizable: false,
				maximizable: false,
				maximized: true,
				content: _html
			});
		}
	});
}

function view(tb) {
	var row = $('#datagrid').datagrid('getSelected');
	if(row == null) {
		S4J.utils.showMessage('请选择一条记录');
		return;
	}
	var rows = $('#datagrid').datagrid('getSelections');
	if(rows.lengt > 1) {
		if(row == null) {
			S4J.utils.showMessage('只能选择一条记录');
			return;
		}
	}
	var params = {
			'patientDoc.docId': row.docId
	};
	win = S4J.utils.openWindow('查看档案','docmgr_liverdocmgr_view',params);
}

function closeWin() {
	$(win).window('destroy');
}